Skip to content

Conversation

@mcgeestocks
Copy link
Contributor

Description:

@mroeschke mentioned that the merged fix for issue #28558 could use a test. This PR adds the missing test for index type equality between the DataFrame and read_json functions.

df = DataFrame()
dfjson = read_json("{}", orient=orient, convert_axes=True)

assert df.index.dtype == dfjson.index.dtype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you compare the entire index?

dfjson = read_json("{}", orient=orient, convert_axes=True)
result = df.json.index
expected = df.index
tm.assert_index_equal(result, expected)

Same for the .columns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update with your suggestions shortly!

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite IO JSON read_json, to_json, json_normalize labels May 15, 2023
@mcgeestocks mcgeestocks marked this pull request as draft May 16, 2023 15:55
@mcgeestocks mcgeestocks marked this pull request as ready for review May 17, 2023 13:45
@mcgeestocks
Copy link
Contributor Author

Updated with your suggestions @mroeschke

mcgeestocks and others added 2 commits May 17, 2023 14:01
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@mcgeestocks
Copy link
Contributor Author

Updated with your latest suggestion @mroeschke. Let me know if there is anything else.

@mroeschke mroeschke added this to the 2.1 milestone May 18, 2023
@mroeschke mroeschke merged commit 1ac7815 into pandas-dev:main May 18, 2023
@mroeschke
Copy link
Member

Thanks @mcgeestocks

topper-123 pushed a commit to topper-123/pandas that referenced this pull request May 22, 2023
* TST: Added test coverage for pd.read_json index type

* Update pandas/tests/io/json/test_pandas.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* add coverage for entire index and columns.

* Update pandas/tests/io/json/test_pandas.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

---------

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
* TST: Added test coverage for pd.read_json index type

* Update pandas/tests/io/json/test_pandas.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* add coverage for entire index and columns.

* Update pandas/tests/io/json/test_pandas.py

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

---------

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IO JSON read_json, to_json, json_normalize Testing pandas testing functions or related to the test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pd.read_json With convert_axes Produces Different Index Type than Empty Frame

2 participants